package com.cskaoyan.market.service.impl;

import com.cskaoyan.market.db.domain.MarketFeedback;
import com.cskaoyan.market.db.domain.MarketFeedbackExample;
import com.cskaoyan.market.db.mapper.MarketFeedbackMapper;
import com.cskaoyan.market.service.MarketAdminFeedbackService;
import com.cskaoyan.market.util.MyBatisUtil;
import com.github.pagehelper.PageHelper;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class MarketAdminFeedBackServiceImpl implements MarketAdminFeedbackService {

    @Override
    public List<MarketFeedback> list(Integer page, Integer limit, String username, Integer id, String sort, String order) {
        SqlSession sqlSession = MyBatisUtil.getSession();

        MarketFeedbackMapper mapper = sqlSession.getMapper(MarketFeedbackMapper.class);

        MarketFeedbackExample example = new MarketFeedbackExample();

        MarketFeedbackExample.Criteria criteria = example.or();

        if (id != null) {
            criteria.andIdEqualTo(id);
        }
        if (!StringUtils.isEmpty(username)) {
            criteria.andUsernameLike("%" + username + "%");
        }

        example.setOrderByClause(sort + " " + order);

        PageHelper.startPage(page, limit);
        List<MarketFeedback> feedbacks = mapper.selectByExample(example);

        return feedbacks;
    }
}
